<template>
	<view class="pet-detail u-skeleton">
		<scroll-view scroll-y="true" class="scroll-Y">
			<view class="detail-swiper u-skeleton-fillet">
				<u-swiper :list="swiperList" height="744" border-radius="0" img-mode="aspectFill" @click="swiperClick"></u-swiper>
			</view>
			<view class="detail-content">
				<view class="content-head">
					<view class="head-text">
						<view class="text-title u-skeleton-fillet">{{dataList.title}}</view>
						<view class="text-red u-skeleton-fillet">{{dataList.price?'¥'+dataList.price:'免费领养'}}</view>
						<view class="text-icon u-skeleton-fillet">
							<view><image src="../../../static/img/dingwei.png" style="width: 22rpx;height: 22rpx;margin: 0 8rpx 0 0;" mode=""></image></view>
							<view>{{dataList.city}}</view>
							<view style="margin-left: 20rpx">{{dataList.createdAt?' 发布于 '+dataList.createdAt:''}}</view>
						</view>
					</view>
					<view class="head-info">
						<view class="info-title u-skeleton-fillet">宠物信息</view>
						<view class="info-head u-skeleton-fillet" @click="setPetData(petData.pid)">
							<view><image style="width: 80rpx;height: 80rpx;border-radius: 100%;" :src="petData.avatar" shape="circle"></image></view>
							<view class="head-base">
								<view class="base-nickname">{{petData.name}}</view>
								<view class="base-message">
									<view class="message-left">{{petData.petFans}} 宠粉</view>
									<view>{{petData.diarys}} 日记</view>
								</view>
							</view>
							<view class="base-right"><u-image width="16rpx" height="36rpx" src="@/static/user/more1.png" shape="circle"></u-image></view>
						</view>
						<view class="info-base u-skeleton-fillet">
							<view class="base-context">
								<view class="context-text">Pid</view>
								<view class="context-matter">{{petData.pid}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">疫苗</view>
								<view class="context-matter">{{dataList.vaccine!==1?dataList.vaccine==2?'免疫中':'已免疫':'未免疫'}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">性别</view>
								<view class="context-matter">{{petData.sex==1?'公':'母'}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">驱虫</view>
								<view class="context-matter">{{dataList.insect==1?'未驱虫':'已驱虫'}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">品种</view>
								<view class="context-matter">{{petData.typeName}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">绝育</view>
								<view class="context-matter">{{dataList.neuter==1?'未绝育':'已绝育'}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">宠龄</view>
								<view class="context-matter">{{dataList.age}}岁</view>
							</view>
							<view class="base-context">
								<view class="context-text">体型</view>
								<view class="context-matter">{{dataList.body!==1?dataList.body==2?'中型':'大型':'小型'}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">状态</view>
								<view class="context-matter">{{dataList.health!==1?dataList.health==2?'患病':'残疾':'健康'}}</view>
							</view>
							<view class="base-context">
								<view class="context-text">毛量</view>
								<view class="context-matter">{{dataList.gross!==1?dataList.gross==2?'短毛':'长毛':'无毛'}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="content-require">
					<view class="require-title">领养要求</view>
					<view class="require-icon-warpper">
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('1') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon1-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon1-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('1') != -1 ? 'color: #333' : 'color: #cccccc'">仅限同城</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('2') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon2-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon2-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('2') != -1 ? 'color: #333' : 'color: #cccccc'">自有住房</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('3') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon3-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon3-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('3') != -1 ? 'color: #333' : 'color: #cccccc'">窗户封闭</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('4') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon4-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon4-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('4') != -1 ? 'color: #333' : 'color: #cccccc'">按时疫苗</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('5') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon5-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon5-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('5') != -1 ? 'color: #333' : 'color: #cccccc'">适龄绝育</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('6') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon6-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon6-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('6') != -1 ? 'color: #333' : 'color: #cccccc'">允许回访</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('7') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon7-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon7-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('7') != -1 ? 'color: #333' : 'color: #cccccc'">日记打卡</view>
						</view>
						<view class="require-icon">
							<view v-if="adoptRequire.indexOf('8') != -1"><u-image width="60rpx" height="60rpx" src="@/static/img/icon8-2.png"></u-image></view>
							<view v-else><u-image width="60rpx" height="60rpx" src="@/static/img/icon8-1.png"></u-image></view>
							<view class="icon-text" :style="adoptRequire.indexOf('8') != -1 ? 'color: #333' : 'color: #cccccc'">领养协议</view>
						</view>
					</view>
					<view class="require-way">
						<view class="way-text">运送方式</view>
						<view style="font-size: 28rpx;font-weight: 600;">{{dataList.transportType==1?'同城（送养人送宠上门）':'同城（领养人上门领宠）'}}</view>
					</view>
				</view>
				<view class="content-master">
					<view class="master-title">铲屎官说</view>
					<view class="master-head">
						<view style="display: flex;"  @click="userClick(dataList.uid)">
							<view><u-image width="80rpx" height="80rpx" :src="dataList.avatar" shape="circle"></u-image></view>
							<view class="head-base">
								<view class="base-nickname">{{dataList.nickname}}</view>
								<view class="base-sign">{{dataList.sign}}</view>
							</view>
						</view>
						<view v-if="dataList.isFollow != '-1'">
							<view class="head-icon" v-if="dataList.isFollow == 0" @click="opsFollow">关注</view>
							<view class="head-icon2" v-if="dataList.isFollow == 1" @click="unFollow">取消关注</view>
						</view>
					</view>
					<view class="master-intro">
						<view class="master-detail">{{dataList.content}}</view>
					</view>
				</view>
				<view class="content-step">
					<view class="step-title">领养流程</view>
					<view class="step-item"> 
						<image src="https://csg-icon.oss-cn-hangzhou.aliyuncs.com/adopt_state.jpeg" style="width: 100%;height: 650rpx;" mode=""></image>
						<!-- <view class="item">
							<view class="item-top"> 
								<view><u-image width="60rpx" height="52rpx" src="@/static/user/step1.png" ></u-image></view>
								<view class="top-text">申请领养,匹配铲屎官</view>
							</view>
							<view class="item-bottom">您最多可以同时发出10次领养申请，1年内最多可以成功领养2次</view>
						</view>
						<view class="item">
							<view class="item-top">
								<view><u-image width="60rpx" height="52rpx" src="@/static/user/step1.png"></u-image></view>
								<view class="top-text">在线签署《领养协议》</view>
							</view>
							<view class="item-bottom">匹配成功后，领养双方需签署电子档《领养协议》，以明确领养双方的权责</view>
						</view>
						<view class="item">
							<view class="item-top">
								<view><u-image width="60rpx" height="52rpx" src="@/static/user/step1.png"></u-image></view>
								<view class="top-text">约定时间，线下交接宠物</view>
							</view>
							<view class="item-bottom">《领养协议》签署完成即可约定合适的时间，领养双方线下当面交接宠物</view>
						</view>
						<view class="item">
							<view class="item-top">
								<view><u-image width="60rpx" height="52rpx" src="@/static/user/step1.png"></u-image></view>
								<view class="top-text">验证领养码，完成领养</view>
							</view>
							<view class="item-bottom">非常关键的一步，宠物交接后，领养双方须尽快验证“领养码”，验证完成后宠物主页即从送养人账号转移至领养人账号</view>
						</view> -->
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="detail-operation">
			<button class="operation-share" open-type="share">
				<view><u-image width="38rpx" height="38rpx" src="@/static/img/share.png" shape="circle"></u-image></view>
				<view>分享</view>
			</button> 
			<view class="operation-btn" v-if="dataList.viewType == 1">
				<view class="operation-btn1" @click="setAdoptUndo">撤销</view>
				<view class="operation-btn1" @click="update">修改</view>
				<view class="operation-btn2" @click="goList">申请人</view>
			</view>
			<view class="operation-btn" v-if="dataList.viewType == 2">
				<view class="operation-btn1" @click="enterChat(dataList.uid, 'private')">私信</view>
				<view class="operation-btn3" @click="adoption">申请领养</view>
			</view>
			<view class="operation-btn" v-if="dataList.viewType == 3">
				<view class="operation-btn1" @click="enterChat(dataList.uid, 'private')">私信</view>
				<view class="operation-btn4">已申请</view>
			</view>
			<view class="operation-btn" v-if="dataList.viewType == 4">
				<view class="operation-btn1" @click="enterChat(dataList.uid, 'private')">私信</view>
				<view class="operation-btn3" @click="goAdopt(dataList.agreementId)">领养协议</view>
			</view>
		</view>
		<u-skeleton :loading="loading" :animation="true" bgColor="#fff"></u-skeleton>
	</view>
</template>

<script>

// import {MasterData,getMasterList} from "../../../lib/Master";
	export default {
		data () {
			return {
				Master: [],
				swiperList: [
					'君不见。'
				],
				operationShow: false,
				id: 0,
				pid: 0,
				dataList: {
					title: '君不见',
					price: '君不见'
				},
				petData: {
					name: '君不见',
					pid: '君不见',
					sex: '君不见'
				},
				adoptRequire: [],
				loading: true
			}
		},
		methods:{
			update(){
				uni.navigateTo({
					url: '../ReleaseAdopt/update?id='+this.id
				})
			},
			setAdoptUndo(){
				let self = this;
				self.$request(self.commonApi.adoptPostCancel+self.id,'POST').then(res=>{
					uni.showToast({
						title: '撤销成功',
						duration:500,
						icon: 'none'
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						})
					},500)
				})
			},
			enterChat (uuid, type) {//进入私聊
				if(uni.getStorageSync('login')){
					uni.setStorageSync('objUuid',uuid)
					let self = this
					let data = uni.getStorageSync('masterList')
					let dataLists = JSON.parse(data)
					dataLists.forEach(item=>{
						if(item.uuid == self.dataList.uid){
							let path = type === self.GoEasy.IM_SCENE.PRIVATE
							// ? '../../../pages/chat/privateChat/privateChat?to=' + self.masterList[1].uuid
							// : '../../../pages/chat/privateChat/privateChat?to=' + self.masterList[1].uuid;
							? '../../../pages/chat/privateChat/privateChat?to=' + item.uuid
							: '../../../pages/chat/privateChat/privateChat?to=' + item.uuid;
							uni.navigateTo({
								url: path
							})
						}
					})
				}else{
					uni.navigateTo({
						url: '../../user/login/index'
					})
				}
				
				// console.log(uuid)
				// uni.navigateTo({
				// 	url: '../../../pages/chat/privateChat/privateChat?to=' + '3bb179af-bcc5-4fe0-9dac-c05688484649'
				// })
			},
			setPetData(e){
				if(this.dataList.uid == uni.getStorageSync('uid')){
					uni.navigateTo({
						url: '../../../pages/pet/home/home?id='+e+'&type='+1
					})
				}else{
					uni.navigateTo({
						url: '../../../pages/pet/home/home?id='+e+'&type='+2
					})
				}

			},
			goList(){
				uni.navigateTo({
					url: '../../user/components/sub/proposers?adoptId='+this.id
				})
			},
			goAdopt (agreementId) {
				uni.navigateTo({
					url: '../agreement/petAgreement?agreementId=' + agreementId
				})
			},
			adoption(){
				uni.navigateTo({
					url: '../adoption/adoption?id='+this.id+'&name='+this.petData.name
				})
			},
			unFollow(){
				this.$request(this.commonApi.userUnPay, 'POST', { beUid:this.dataList.uid }, 'application/json').then(res=>{
					let items = res.data
					if (items.code !== 200) {
						uni.showToast({
							title: items.msg,
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '已取消关注',
							icon: 'none'
						})
						this.getData()
						this.getPet()
					}
				})
			},
			opsFollow(){
				this.$request(this.commonApi.userPay, 'POST', { beUid: this.dataList.uid }, 'application/json').then(res=>{
					let items = res.data
					if (items.code !== 200) {
						uni.showToast({
							title: items.msg,
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '关注成功',
							icon: 'none'
						})
						this.getData()
						this.getPet()
					}
				})
			},
			getData(){
				let self = this;
				this.loading = true
				self.$request(self.commonApi.petAdopt + self.id, 'GET', {}).then(res=>{
					let data = res.data.data
					let items = res.data
					self.petData = items.data.petInfoDto
					self.loading = false
					if (items.code !== 200) {
						uni.showToast({
							title: items.msg,
							icon: 'none'
						})
					} else {
						if (items.data.contentImg !== null) {
							self.swiperList = items.data.contentImg.split(',')
						}
						self.dataList = items.data
						self.adoptRequire = items.data.adoptRequire.split(",")
					}
				})
			},
			// 铲屎官跳转
			userClick (uid) {
				uni.navigateTo({
					url: '../../user/components/profile?uid=' + uid
				})
			},
			// 点击轮播图
			swiperClick (index) {
				uni.previewImage({
					urls: this.swiperList,
					current: index,
					success: () => {
					},
					fail: () => {
						uni.showToast({
							title: '预览图片失败',
							icon: 'none'
						});
					}
				});
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getData()
			// this.Master = [6,9,8]
			// console.log(this.Master)
			
		},
		onShareAppMessage(res) {
			return {
				title: this.dataList.title,
				path: `/myPackageA/index/detail/petDetails?id=${this.id}?uid=${this.dataList.pid}`,
				imageUrl: this.swiperList[0],
				success(res) {
					console.log('分享成功');
				},
				fail(err) {
					console.log('分享失败');
				}
			};
		}
	}
</script>

<style lang="scss" scoped>
	.base-right{
		image{
			margin-top: 15rpx;
		}
	}
	.pet-detail {
		height: 100vh;
		position: relative;
		.scroll-Y {
			height: calc(100vh - 120rpx);
		}
		.detail-swiper {
			width: 100%;
			height: 744rpx;
		}
		.detail-content {
			width: 100%;
			padding: 0 30rpx;
			.content-head {
				padding: 20rpx 0;
				background-color: #fff;
				width: 100%;
				border-radius: 24rpx 24rpx 0px 0px;
				border-bottom: 2rpx solid #F9F9F9;
				.head-text {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					border-bottom: 1px solid #F6F6F6;
					.text-title {
						font-size: 36rpx;
						font-weight: 700;
						color: #333333;
						line-height: 44rpx;
					}
					.text-red {
						font-size: 30rpx;
						font-weight: 700;
						color: #ED5D4D;
						line-height: 44rpx;
						margin: 10rpx 0;
					}
					.text-icon {
						font-size: 22rpx;
						font-weight: 400;
						color: #999999;
						line-height: 32rpx;
						width: 100%;
						display: flex;
						flex-direction: row;
						align-items: center;
						margin-bottom: 20rpx;
					}
				}
				.head-info {
					padding-top: 20rpx;
					.info-title {
						font-size: 28rpx;
						font-weight: 700;
						color: #333333;
						line-height: 40rpx;
					}
					.info-head {
						margin: 20rpx 0;
						display: flex;
						.head-base {
							width: 100%;
							height: 100%;
							margin-left: 20rpx;
							display: flex;
							flex-direction: column;
							// justify-content: space-between;
							.base-nickname {
								font-size: 30rpx;
								font-weight: 700;
								color: #333333;
								line-height: 36rpx;
							}
							.base-message {
								font-size: 24rpx;
								font-weight: 400;
								color: #999999;
								line-height: 34rpx;
								display: flex;
								margin-top: 7rpx;
								.message-left {
									margin-right: 20rpx;
								}
							}
						}
					}
					.info-base {
						display: flex;
						flex-wrap: wrap;
						.base-context {
							width: 345rpx;
							display: flex;
							font-size: 28rpx;
							font-weight: 400;
							line-height: 40rpx;
							padding: 10rpx;
							.context-text {
								flex: 1;
								color: #999999;
							}
							.context-matter {
								flex: 1;
								font-size: 28rpx;
								font-weight: 600;
								color: #333333;
							}
						}
					}
				}
			}
			.content-require {
				background-color: #fff;
				border-bottom: 2rpx solid #F6F6F6;
				padding: 30rpx 0;
				.require-title {
					font-size: 28rpx;
					font-weight: 700;
					color: #333333;
					line-height: 40rpx;
				}
				.require-icon-warpper {
					display: flex;
					flex-wrap: wrap;
					border-bottom: 1px solid #F6F6F6;
					padding-bottom: 10rpx;
					.require-icon {
						width: 172rpx;
						height: 124rpx;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						padding: 10rpx;
						.icon-text {
							font-size: 28rpx;
							font-weight: 400;
							color: #333333;
							line-height: 40rpx;
						}
					}
				}
				.require-way {
					font-size: 28rpx;
					font-weight: 400;
					color: #333333;
					line-height: 40rpx;
					display: flex;
					justify-content: space-between;
					padding-top: 30rpx;
					.way-text {
						color: #999999;
					}
				}
			}
			.content-master {
				background-color: #fff;
				padding: 30rpx 0;
				border-bottom: 2rpx solid #f9f9f9;
				.master-title {
					font-size: 28rpx;
					font-weight: 700;
					color: #333333;
					line-height: 40rpx;
				}
				.master-head {
					padding: 20rpx 0;
					display: flex;
					align-items: center;
					.head-base {
						margin-left: 20rpx;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: 445rpx;
						.base-nickname {
							font-size: 28rpx;
							font-weight: 600;
							color: #333333;
							line-height: 40rpx;
						}
						.base-sign {
							font-size: 24rpx;
							font-weight: 400;
							color: #999999;
							line-height: 34rpx;
							overflow:hidden;
							text-overflow:ellipsis;
							white-space:nowrap;
							width: 445rpx;
						}
					}
					.head-icon {
						width: 140rpx;
						height: 48rpx;
						background: rgba(255, 247, 235, 1);
						border-radius: 8rpx;
						font-size: 28rpx;
						font-weight: 600;
						color: rgba(255, 154, 0, 1);
						line-height: 48rpx;
						text-align: center;
					}
					.head-icon2 {
						width: 140rpx;
						height: 48rpx;
						background: #f2f2f2;
						border-radius: 8rpx;
						font-size: 28rpx;
						font-weight: 600;
						color: black;
						line-height: 48rpx;
						text-align: center;
					}
				}
				.master-intro {
					margin-top: 15rpx;
					.master-detail {
						border-radius: 12rpx;
						background-color: #F6F6F6;
						padding: 20rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #333333;
						line-height: 34rpx;
					}
				}
			}
			.content-step {
				background-color: #fff;
				padding-top: 30rpx;
				.step-title {
					font-size: 28rpx;
					font-weight: 700;
					color: #333333;
					line-height: 40rpx;
				}
				.step-item {
					width: 100%;
					// padding: 30rpx 0;
					// .item {
					// 	padding: 30rpx 0;
					// 	border-bottom: 2rpx solid #f9f9f9;
					// 	.item-top {
					// 		display: flex;
					// 		align-items: center;
					// 		font-size: 28rpx;
					// 		font-weight: 700;
					// 		color: #313131;
					// 		line-height: 36rpx;
					// 		.top-text {
					// 			margin-left: 15rpx;
					// 		}
					// 	}
					// 	.item-bottom {
					// 		font-size: 26rpx;
					// 		font-weight: 400;
					// 		color: #999999;
					// 		line-height: 36rpx;
					// 		margin-top: 22rpx;
					// 	}
					// }
				}
			}
		}
		.detail-operation {
			height: 120rpx;
			padding: 30rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #333333;
			display: flex;
			background-color: #fff;
			align-items: center;
			width: 100%;
			position: absolute;
			bottom: 0;
			button {
				margin: 0;
				background-color: #fff;
				padding: 0;
			}
			button::after {
				border: none;
			}
			.operation-share {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				font-size: 20rpx;
				font-weight: 400;
				color: #4D4D4D;
				line-height: 28rpx;
			}
			.operation-btn {
				flex: 1;
				display: flex;
				justify-content: space-between;
				margin-left: 40rpx;
				font-size: 28rpx;
				font-weight: 400;
				.operation-btn1 {
					width: 160rpx;
					height: 64rpx;
					background: #F6F6F6;
					border-radius: 12rpx;
					line-height: 64rpx;
					text-align: center;
				}
				.operation-btn2 {
					width: 210rpx;
					height: 64rpx;
					background: rgba(255, 154, 0, 1);
					border-radius: 12rpx;
					color: #fff;
					line-height: 64rpx;
					text-align: center;
				}
				.operation-btn4{
					width: 400rpx;
					height: 64rpx;
					background: #F6F6F6;
					border-radius: 12rpx;
					line-height: 64rpx;
					text-align: center;
				}
				.operation-btn3 {
					width: 400rpx;
					height: 64rpx;
					background: #FFBB00;
					border-radius: 12rpx;
					color: #fff;
					line-height: 64rpx;
					text-align: center;
				}
			}
		}
	}
</style>
